﻿
var status;
var selstatus = -1;
var itemList = new Array();
var inventoryType;
var deleteSlot;
var deleteQuantity;
var xianshi;

var FY = "#fMap/MapHelper.img/weather/cn10th/0#"; //枫叶
var wn1 = "#fMap/MapHelper.img/weather/snowbear/0#"; //雪狗
var wn2 = "#fMap/MapHelper.img/weather/snowbear/1#"; //雪海豹
var wn3 = "#fMap/MapHelper.img/weather/snowbear/2#"; //雪企鹅
var wn5 = "#fMap/MapHelper.img/weather/5000days/1#"; //绿水灵
var wn6 = "#fMap/MapHelper.img/weather/5000days/3#"; //花蘑菇
var icon = Array(wn1, wn2, wn3, wn5, wn6);
var ic = icon[Math.floor(Math.random() * icon.length)];

function start() {
	status = -1;
	action(1, 0, 0);
}

function action(mode, type, selection) {
	if (status == 3 && mode == 0) {
		cm.dispose();
		return;
	} else if (mode <= 0) {
		cm.dispose();
		return;
	} else {
		if (mode == 1) {
			status++;
		} else {
			status--;
		}
		if (status == 0) {

			var selStr = "";
			selStr += "	   " + FY + "  #d#e" + cm.getServerName() + " 背包清理#n#k" + FY + "\r\n \r\n#b";
			selStr += " #L0# " + ic + "#b 指定清理#k（#d仅仅删除,#e所指定#n的物品）#k#l\r\n";
			selStr += " #L1# " + ic + "#b 一键清理#k（#r一键删除#e该栏目全部#n物品）#k#l\r\n \r\n";
			cm.sendSimple(selStr);

		} else {
			if (selstatus == -1) {
				selstatus = selection;
			}
			switch (selstatus) {
			case 0:
				deleteItemBySlot(selection);
				break;
			case 1:
				deleteItemBySlot1(selection);
				break;
			case 2:
				deleteItemBySlot2(selection);
				break;
			}
		}
	}
}

function deleteItemBySlot(selection) {
	if (status == 1) {
		text = "\t\t#e- 请选择要清理的道具类型 -#n\r\n#b";
		text += "\t\t\t\t#L1#" + ic + "装备栏#l\r\n";
		text += "\t\t\t\t#L2#" + ic + "消耗栏#l\r\n";
		text += "\t\t\t\t#L4#" + ic + "其它栏#l\r\n";
		text += "\t\t\t\t#L3#" + ic + "设置栏#l\r\n";
		text += "\t\t\t\t#L5#" + ic + "特殊栏#l\r\n";
		cm.sendSimple(text);
	} else if (status == 2) {
		inventoryType = selection;
		var aaa = false;
		inv = cm.getInventory(inventoryType);
		text = "\t\t\t  #e- 请选择要清理的道具 -#n\r\n\r\n#b";
		for (var i = 1; i <= inv.getSlotLimit(); i++) {
			var it = inv.getItem(i);
			if (it == null) {
				continue;
			}
			var itemid = it.getItemId();
			aaa = true;
			text += "#L" + i + "##v" + itemid + "##z" + itemid + "#\r\n#l";
		}
		if (!aaa) {
			cm.playerMessage(1, "该栏中没有道具");
			cm.dispose();
			return;
		}
		cm.sendSimple(text + "#k");
	} else if (status == 3) {
		var item = cm.getInventory(inventoryType).getItem(selection);
		deleteSlot = selection;
		deleteQuantity = item.getQuantity();
		text = "#e确定要清理#r#v" + item.getItemId() + "##z" + item.getItemId() + "# " + deleteQuantity + "个 #k吗？";
		cm.sendYesNo(text);
	} else if (status == 4) {
		cm.removeSlot(inventoryType, deleteSlot, deleteQuantity);
		cm.sendOk("清理成功，祝你游戏愉快~");
		cm.playerMessage(-1, "删除道具成功!!");
		status = 0;
	}
}

function deleteItemBySlot1(selection) {
	if (status == 1) {
		text = "\t\t#e- 请选择要清理的道具类型 -#n\r\n#b";
		text += "\t\t\t\t#L1#" + ic + "装备栏#l\r\n";
		text += "\t\t\t\t#L2#" + ic + "消耗栏#l\r\n";
		text += "\t\t\t\t#L4#" + ic + "其它栏#l\r\n";
		text += "\t\t\t\t#L3#" + ic + "设置栏#l\r\n";
		text += "\t\t\t\t#L5#" + ic + "特殊栏#l\r\n";
		cm.sendSimple(text);
	} else if (status == 2) {
		inventoryType = selection;
		if (selection == 1) {
			xianshi = "装备栏";
		} else if (selection == 2) {
			xianshi = "消耗栏";
		} else if (selection == 4) {
			xianshi = "其他栏";
		} else if (selection == 3) {
			xianshi = "设置栏";
		} else if (selection == 5) {
			xianshi = "特殊栏";
		}
		var aaa = false;
		inv = cm.getInventory(inventoryType);
		text = "#r" + xianshi + "#b 内有以下道具，你确定都要清理吗？#k\r\n";
		for (var i = 1; i <= inv.getSlotLimit(); i++) {
			var it = inv.getItem(i);
			if (it == null) {
				continue;
			}
			var itemid = it.getItemId();
			aaa = true;
			text += "#e道具：#n#v" + itemid + "##b#z" + itemid + "##k，#e数量：#n#r" + it.getQuantity() + "#k 个。\r\n";
		}
		if (!aaa) {
			cm.playerMessage(1, "该栏中没有道具");
			cm.dispose();
			return;
		}
		cm.sendYesNo(text);
	} else if (status == 3) {
		inv = cm.getInventory(inventoryType);
		text = "您成功清理了以下道具，祝您游戏愉快！~\r\n";
		for (var i = 1; i <= inv.getSlotLimit(); i++) {
			var it = inv.getItem(i);
			if (it == null) {
				continue;
			}
			var itemid = it.getItemId();
			cm.removeSlot(inventoryType, i, it.getQuantity());
		}
		cm.sendOk("您成功清理了道具，祝您游戏愉快！");
		cm.playerMessage(-1, "您执行了删除操作!!");
		status = 0;
	}
}
